"set mousemodel=extend 
"set number
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Import external source
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"source $VIM/vim70/mswin.vim

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible " get out of horrible vi-compatible mode
filetype on " detect the type of file
set history=100 " How many lines of history to remember
set ffs=dos,unix,mac " support all three, in this order
filetype plugin indent on " load filetype plugins
set viminfo+=! " make sure it can save viminfo
set isk+=_,$,@,%,#,- " none of these should be word dividers, so make them not be

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Theme/Colors
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"set background=dark " we are using a dark background
"syntax on " syntax highlighting on
"colorscheme desert " my theme for gui
"colorscheme evening " my theme for terminal

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Files/Backups
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nobackup " make backup file
set makeef=error.err " When using make, where should it dump the file

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vim UI
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set wildmenu " turn on wild menu
set ruler " Always show current positions along the bottom 
set cmdheight=1 " the command bar is 1 high
set number " turn off line numbers
set numberwidth=4 " minimum width to use for the number column,not a fix size
set hid " you can change buffer without saving
set backspace=2 " make backspace work normal
set whichwrap+=<,>,h,l  " backspace and cursor keys wrap to
set mouse=a " use mouse everywhere
set shortmess=atI " shortens messages to avoid 'press a key' prompt 
set report=0 " tell us when anything is changed via :...
set lz " do not redraw while running macros (much faster) (LazyRedraw)
" make the splitters between windows be blank
set fillchars=vert:\ ,stl:\ ,stlnc:\
set lsp=0 " space it out a little more (easier to read)

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Visual Cues
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set showmatch " show matching brackets
set hlsearch " do highlight searched for phrases
set incsearch " BUT do highlight as you type you search phrase
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$ " what to show when I hit :set list
"set so=10 " Keep 10 lines (top/bottom) for scope
set novisualbell " don't blink
set noerrorbells " no noises
set laststatus=2 " always show the status line

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" File encode
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set encoding=utf-8
set fileencoding=chinese
set fileencodings=ucs-bom,utf-8,chinese

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Text Formatting/Layout
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set formatoptions+=mM " for charactors fold and patch
set ai " autoindent
set si " smartindent 
set cindent " do c-style indenting
set tabstop=4 " tab spacing (settings below are just to unify it)
set softtabstop=4 " unify
set shiftwidth=4 " unify 
set noexpandtab " real tabs please!
set nowrap " do not wrap lines  
set smarttab " use tabs at the start of a line, spaces elsewhere

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Folding
" Enable folding, but by default make it act like folding is off, because folding is annoying in anything but a few rare cases
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set foldenable " Turn on folding
set foldlevel=100 " Don't autofold anything (but I can still fold manually)
set foldopen-=search " don't open folds when you search into them
set foldopen-=undo " don't open folds when you undo stuff

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" File Explorer
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:explVertical=1 " should I split verticially
let g:explWinSize=35 " width of 35 pixels

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Win Manager
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"let g:winManagerWidth=35 " How wide should it be( pixels)
let g:winManagerWindowLayout = 'FileExplorer,TagsExplorer|BufExplorer' " What windows should it

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CTags and Taglist
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let Tlist_Ctags_Cmd = "/usr/bin/ctags-exuberant" " Location of my ctags
let Tlist_Sort_Type = "name" " order by 
let Tlist_Use_Right_Window = 0 " split to the left side of the screen
let Tlist_Compart_Format = 1 " show small meny
let Tlist_Exist_OnlyWindow = 1 " if you are the last, kill yourself
let Tlist_File_Fold_Auto_Close = 0 " Do not close tags for other files
let Tlist_Enable_Fold_Column = 0 " Do not show folding tree
let Tlist_Use_Right_Window=1     "列表放在屏幕的右侧
let Tlist_File_Fold_Auto_Close=1 "当前不被编辑的文件的方法列表自动折叠起来 这样可以节约一些屏幕空间

set tags=./tags,./../tags,./../../tags,./**/tags,tags " which tags files CTRL-] will search
set autochdir " auto change the current dierctory when you open the file or window or any other buffer
set makeef=makeerror.err
set path=.,./../**,/usr/include/*,,

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Minibuf
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:miniBufExplTabWrap = 1 " make tabs show complete (no broken on two lines)
let g:miniBufExplModSelTarget = 1

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Matchit
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let b:match_ignorecase = 1

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Mappings,I don't need any mapping now
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"map <right> <ESC>:MBEbn<RETURN> " right arrow (normal mode) switches buffers  (excluding minibuf)
"map <left> <ESC>:MBEbp<RETURN> " left arrow (normal mode) switches buffers (excluding minibuf) 
"map <up> <ESC>:Sex<RETURN><ESC><C-W><C-W> " up arrow (normal mode) brings up a file list
"map <down> <ESC>:Tlist<RETURN> " down arrow  (normal mode) brings up the tag list
"map <A-i> i <ESC>r " alt-i (normal mode) inserts a single char, and then switches back to normal
"map <F2> <ESC>ggVG:call SuperRetab()<left>
"map <F12> ggVGg? " encypt the file (toggle)

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Autocommands
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd BufEnter * :syntax sync fromstart " ensure every file does syntax highlighting (full)
"autocmd GUIEnter * :simalt ~x -- " having it auto maximize the screen
au BufEnter /usr/include/c++/*   setf cpp " all the file under the directory are recognized as cpp files by vim

" if there are any error space(the end of line or before the tabs) in c/c++ code,highlight it
"if $VIM_HATE_SPACE_ERRORS != '0'
"let c_space_errors=1
"endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Useful abbrevs, I don't need any iab now
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"iab xasp <%@language=jscript%><CR><%<CR><TAB><CR><BS>%><ESC><<O<TAB>
"iab xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>



"************************************************
""vim 的配置文件源自lxb，修改人Kevin
"在Fedora Core 6 上使用
""修改时间：2007－4－18
"*************************************************
""设定文件编码类型，彻底解决中文编码问题
let &termencoding=&encoding
set fileencodings=utf-8,gbk,ucs-bom,cp936

"**************************************************
"设定文件编码类型，彻底解决中文编码问题
let &termencoding=&encoding
set fileencodings=utf-8,gbk,ucs-bom,cp936

"**************************************************
colorscheme evening " 设置工作模式为夜间
filetype plugin on  " 自动识别文件类型，自动匹配对应的
" plugin.vim 所对应的文件
set bs=indent,eol,start " 容许使用退格键

"打开自动缩进和Ｃ语言的缩进风格
"制定Ｃ语言的缩进风格
set autoindent cindent cinoptions=g0 "

"容许使用退格和Del键
set backspace=indent,eol,start

"设置备份时的行为为覆盖
set backupcopy=yes

"设定状态列的行数为 1
set cmdheight=1

" 自动补全(ctrl-p)时的一些选项：
" 多于一项时显示菜单，最长选择，
" 显示当前选择的额外信息
set completeopt=menu,longest,preview

"设定编码为 cp936，否则将无法显示繁体字
"set encoding=cp936
set encoding=utf-8

"将 tab 键转换为空格
set expandtab

" 启动输入自动完成功能,
"当输入前三个字母时,会自动完成其余部分,按tab键确认
"需要把word_complete.vim文件放到plugin目录下
"autocmd BufEnter * call DoWordComplete()

"使得注释换行时自动加上前导的空格和星号
set formatoptions=tcqro

"允许在有未保存的修改时切换缓冲区，
"此时的修改由切换由 vim 负责保存
set hidden 

" 设置冒号命令和搜索命令的命令历史列表的长度为 50
set history=50 

" 搜索时高亮显示被找到的文本
set hlsearch   

" 搜索时忽略大小写，但在有一个或以上大写字母时
" 仍保持对大小写敏感
set ignorecase smartcase

" 输入搜索内容时就显示搜索结果
set incsearch

" 设定在任何模式下鼠标都可用
set mouse=a  

" 覆盖文件时不备份
set nobackup

" 设定 gvim 运行在增强模式下
set nocompatible 

" 在单词中间断行
set nolinebreak 

" 显示行号
set number

" 打开状态栏标尺
set ruler  

" 设定光标离窗口上下边界 5 行时窗口自动滚动
"set scrolloff=5

" 设定 << 和 >> 命令移动时的宽度为 4
set shiftwidth=4 

" 在状态栏显示目前所执行的指令，未完成的指令片段亦
" 会显示出来
set showcmd 

" 使得按退格键时可以一次删掉 4 个空格
"（不足 4 个时删掉所有剩下的空格）
set softtabstop=4 

" 设定 tab 长度为 4
set tabstop=4

" 设定退格键、空格键以及左右方向键在行首行尾时的
" 行为，不影响 h 和 l 键
set whichwrap=b,s,<,>,[,] 

" 自动换行显示
set wrap 

" 自动语法高亮
syntax on  
syntax enable
" 设置编码
"set enc=chinese
" 设置文件编码

set imcmdline 
"set guifont="Serif 14"
set fenc=chinese
" 设置文件编码检测类型及支持格式
set fencs=utf-8,gbk,ucs-bom,gb18030,gb2312,cp936
" 指定菜单语言
"set langmenu=zh_CN.GBK
set langmenu=zh_CN.UTF-8
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim 
"set cmdheight=0 " the command bar is 1 high
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Theme/Colors
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"set background=dark " we are using a dark background
"syntax on " syntax highlighting on
"colorscheme desert " my theme for gui
"colorscheme evening " my theme for terminal

"*********************************************
" 类似于 editplus 自动完成的实现
function! Eatchar(pat)
let s:c = nr2char(getchar())
return (s:c =~ a:pat) ? '' : s:c
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" vim7.1在windows下的编码设置。By Huadong.Liu
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
if has("win32")
set fileencoding=chinese
else
set fileencoding=utf-8
endif
"解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"解决consle输出乱码
language messages zh_CN.utf-8
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Multi-encoding setting, MUST BE IN THE BEGINNING OF .vimrc!
"
if has("win32")
if has("multi_byte")
    " When 'fileencodings' starts with 'ucs-bom', don't do this manually
    "set bomb
    set fileencodings=ucs-bom,chinese,taiwan,japan,korea,utf-8,latin1
    " CJK environment detection and corresponding setting
    if v:lang =~ "^zh_CN"
        " Simplified Chinese, on Unix euc-cn, on MS-Windows cp936
        set encoding=chinese
        set termencoding=chinese
        if &fileencoding == ''
            set fileencoding=chinese
        endif
    elseif v:lang =~ "^zh_TW"
        " Traditional Chinese, on Unix euc-tw, on MS-Windows cp950
        set encoding=taiwan
        set termencoding=taiwan
        if &fileencoding == ''
            set fileencoding=taiwan
        endif
    elseif v:lang =~ "^ja_JP"
        " Japanese, on Unix euc-jp, on MS-Windows cp932
        set encoding=japan
        set termencoding=japan
        if &fileencoding == ''
            set fileencoding=japan
        endif
    elseif v:lang =~ "^ko"
        " Korean on Unix euc-kr, on MS-Windows cp949
        set encoding=korea
        set termencoding=korea
        if &fileencoding == ''
            set fileencoding=korea
        endif
    endif
    " Detect UTF-8 locale, and override CJK setting if needed
    if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
        set encoding=utf-8
    endif
else
    echoerr 'Sorry, this version of (g)Vim was not compiled with "multi_byte"'
endif
endif

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
an 20.4109 &Edit.-SEP6- <Nop>
an 20.4109.10 &Edit.Encoding.&GBK :set encoding=gbk<CR>
an 20.4109.11 &Edit.Encoding.&Big5 :set encoding=big5<CR>
an 20.4109.12 &Edit.Encoding.&UTF-8 :set encoding=utf-8<CR>

an 20.4119.10 &Edit.Fileencodings.&GBK :set fileencodings=gbk<CR>
an 20.4119.11 &Edit.Fileencodings.&Big5 :set fileencodings=big5<CR>
an 20.4119.12 &Edit.Fileencodings.&UTF-8 :set fileencodings=utf-8<CR>

an 20.4139 &Edit.gb\ \ convert.gb->big5 :%!autogb -i gb -o big5<CR>
an 20.4139 &Edit.gb\ \ convert.gb->utf8 :%!autogb -i gb -o utf8<CR>

an 20.4149 &Edit.big5\ \ convert.big5->gb :%!autogb -i big5 -o gb<CR>
an 20.4149 &Edit.big5\ \ convert.big5->utf8 :%!autogb -i big5 -o utf8<CR>

an 20.4159 &Edit.utf8\ \ convert.utf8->gb :%!autogb -i utf8 -o gb<CR>
an 20.4159 &Edit.utf8\ \ convert.utf8->big5 :%!autogb -i utf8 -o big5<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"set diffexpr=MyDiff()
set diffexpr=MYDiff()
function MYDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  let eq = ''
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      let cmd = '""' . $VIMRUNTIME . '\diff"'
      let eq = '"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"图形界面与字符界面的分别设置
if (has("gui_running")) "图型界面设置
    "set nowrap          "不折行
    "set guioptions+=b   "水平滚动条
    "colo torte          "配色方案
else                    "字符界面设置
    set wrap            "折行
    "colo ron            "配色方案
endif

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"let g:winManagerWindowLayout = "FileExplorer" "不喜欢 bufexplorer 插件的话 命令禁用它
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("gui_running") 
    "colorscheme koehler 
    colorscheme desert " my theme for gui
else 
    colorscheme evening 
endif 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" cscope setting
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"   if has("cscope")
"     set csprg=/usr/bin/cscope
"     set csto=1
"     set cst
"     set nocsverb
"     " add any database in current directory
"     if filereadable("cscope.out")
"         "cs add cscope.out
"     endif
"     set csverb
"   endif
"
"   nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>
"   nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>
"   nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>
"   nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>
"   nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>
"   nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
"   nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
"   nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:miniBufExplMapWindowNavVim = 1 
let g:miniBufExplMapWindowNavArrows = 1 
let g:miniBufExplMapCTabSwitchBufs = 1 
let g:miniBufExplModSelTarget = 1 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <c-w><c-f> :FirstExplorerWindow<cr> 
map <c-w><c-b> :BottomExplorerWindow<cr> 
map <c-w><c-t> :WMToggle<cr> 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"折叠设置
set foldmethod=marker
"set foldmethod=foldoption
set cindent
set fdm=indent
" 继承前一行的缩进方式，特别适用于多行注释 
set autoindent 
" 为C程序提供自动缩进 
set smartindent 
" 使用C样式的缩进 
set cindent 
set fdm=indent
""----------------------------------------------
"au BufWinLeave * mkview
"au BufWinEnter * silent loadview
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""
" Tag list (ctags)
""""""""""""""""""""""""""""""
fun! MySys()
  return "windows"
endfun

if MySys() == "windows"                "设定windows系统中ctags程序的位置
  let Tlist_Ctags_Cmd = 'ctags'
elseif MySys() == "linux"              "设定linux系统中ctags程序的位置
  let Tlist_Ctags_Cmd = '/usr/bin/ctags'
endif
"let Tlist_Show_One_File = 1            "不同时显示多个文件的tag，只显示当前文件的
let Tlist_Exit_OnlyWindow = 1          "如果taglist窗口是最后一个窗口，则退出vim
let Tlist_Use_Right_Window = 1         "在右侧窗口中显示taglist窗口 
let Tlist_Auto_Open=0                 "打开文件时自动打开taglist窗口
let Tlist_WinWidth = 25               "我觉得它太宽了，设置一下变折一些
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:winManagerWindowLayout='FileExplorer|TagList'
"nmap wm :WMToggle<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

""""""""""""""""""""""""""""""
" Statusline
""""""""""""""""""""""""""""""
"Always hide the statusline
set laststatus=2

function! CurDir()
 let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g")
 return curdir
endfunction

"Format the statusline
set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c\ %P\ \ %{VimBuddy()}
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
noremap <silent> <F11> :cal VimCommanderToggle()<CR>
"-------------------------------------------------------------------
"注释下面两句 解决打开新窗口老提示出错的问题
""----------------------------------------------
"au BufWinLeave * mkview
"au BufWinEnter * silent loadview
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


function! MyGrep(...)
  if a:0 < 2
    echo "Usage: MyGrep <options> <pattern> <dir>"
    echo 'Example: MyGrep -r "cow" ~/Desktop/*'
    return
  endif
  if a:0 == 2
    let options = '-rsinI'
    let pattern = a:1
    let dir = a:2
  else
    let options = a:1 . 'snI'
    let pattern = a:2
    let dir = a:3
  endif
  let exclude = 'grep -v "/.svn"'
  let cmd = 'grep '.options.' '.pattern.' '.dir. '| '.exclude
  let cmd_output = system(cmd)
  if cmd_output == ""
    echomsg "Pattern " . pattern . " not found"
    return
  endif

  let tmpfile = tempname()
  exe "redir! > " . tmpfile
  silent echon '[grep search for "'.pattern.'" with options "'.options.'"]'."\n"
  silent echon cmd_output
  redir END

  let old_efm = &efm
  set efm=%f:%\\s%#%l:%m

  execute "silent! cgetfile " . tmpfile
  let &efm = old_efm
  botright copen

  call delete(tmpfile)
endfunction
command! -nargs=* -complete=file MyGrep call MyGrep(<f-args>)


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"   function! SmartTOHtml()
"      TOhtml
"      try
"       %s/&quot;\s\+\*&gt; \(.\+\)</" <a href="#\1" style="color: cyan">\1<\/a></g
"       %s/&quot;\(-\|\s\)\+\*&gt; \(.\+\)</" \&nbsp;\&nbsp; <a href="#\2" style="color: cyan;">\2<\/a></g
"       %s/&quot;\s\+=&gt; \(.\+\)</" <a name="\1" style="color: #fff">\1<\/a></g
"      catch
"      endtry
"      exe ":write!"
"      exe ":bd"
"   endfunction
"   --------------------------------------------------------------------------------------------
"   #!/bin/bash
"
"   find . -name "*.h" -o -name "*.c" -o -name "*.cc" -o -iname "*.cpp" > cscope.files
"   cscope -bkq -i cscope.files
"   #ctags -R 
"       0 或 s: 查找本 C 符号 查找C语言符号，即查找函数名、宏、枚举值等出现的地方 
"    	1 或 g: 查找本定义  查找函数、宏、枚举等定义的位置，类似ctags所提供的功能 
"    	2 或 d: 查找本函数调用的函数
"    	3 或 c: 查找调用本函数的函数
"    	4 或 t: 查找本字符串
"    	6 或 e: 查找本 egrep 模式  相当于egrep功能，但查找速度快多了 
"    	7 或 f: 查找本文件 查找并打开文件，类似vim的find功能
"    	8 或 i: 查找包含本文件的文件
"
"   --------------------------------------------------------------------------------------------
"--------------------------------------------------------------------------------------------
"结合make和quickfix窗口写了个脚本，可以在不脱离vi的情况下编译单个文件。
"具体用法：
"1、把下列代码加入你的.vimrc文件（~\.vimrc）
""this script use to excute make in vim and open quickfix window
nmap B :call Do_make()<cr><cr><cr>
nmap C :cclose<cr>
function Do_make()
    let filename = bufname("%")
    let suffix_pos = stridx(filename, ".c")
    if suffix_pos == -1
        return
    else
        let target = strpart(filename,0,suffix_pos)
    endif
    let target = "make " . target

    execute target
    execute "copen"
endfunction

" 2. 在vi中nomal模式下（也就是命令模式，不是按了冒号那个命令模式哈）
" 按shift+b编译程序。 如果有错误quickfix窗口会给出错误行以及错误信息，在上面按回车 会跳到出错行
" 按shift+c关闭quickfix窗口。
" 注意：shift+c在vi中默认是删除该行光标后所有字符并进入输入模式。如果你经常用这个热键，请自己重新map。只支持c文件
"--------------------------------------------------------------------------------------------
"   :inoremap ( ()<ESC>i
"   :inoremap ) <c-r>=ClosePair(')')<CR>
"   :inoremap { {}<ESC>i
"   :inoremap } <c-r>=ClosePair('}')<CR>
"   :inoremap [ []<ESC>i
"   :inoremap ] <c-r>=ClosePair(']')<CR>
"   :inoremap < <><ESC>i
"   :inoremap > <c-r>=ClosePair('>')<CR>
"
"   function ClosePair(char)
"       if getline('.')[col('.') - 1] == a:char
"           return "\<Right>"
"       else
"           return a:char
"       endif
"   endf
"--------------------------------------------------------------------------------------------
"   
"--------------------------------------
""Toggle Menu and Toolbar
set guioptions-=m
set guioptions-=T
map <silent> <F2> :if &guioptions =~# 'T' <Bar>
        \set guioptions-=T <Bar>
        \set guioptions-=m <bar>
    \else <Bar>
        \set guioptions+=T <Bar>
        \set guioptions+=m <Bar>
    \endif<CR>
"--------------------------------------
"   
" python auto-complete code
" Typing the following (in insert mode):
"   os.lis<Ctrl-n>
" will expand to:
"   os.listdir(
" Python 自动补全功能，只需要反覆按 Ctrl-N 就行了
"if has("autocmd")
  "autocmd FileType python set complete+=k~/.vim/tools/pydiction
  "autocmd FileType python set complete+=k~/vim/tools/pydiction
"endif
"===============================================
autocmd FileType c set omnifunc=ccomplete#Complete
set cindent 
set ai
"   if &bg == "dark"  " 根据你的背景色风格来设置不同的书签颜色
"       highlight SignColor ctermfg=white ctermbg=blue guifg=wheat guibg=peru
"   else             "主要就是修改guibg的值来设置书签的颜色
"       highlight SignColor ctermbg=white ctermfg=blue guibg=grey guifg=RoyalBlue3
"   endif
"
"--------------------------------------
"txt2tags file
au BufNewFile,BufRead *.t2t               setf txt2tags
filetype plugin indent on " load filetype plugins
"--------------------------------------
"禁用nmap B和C
nunmap B
nunmap C

"
if has("win32") "在win32下
    "colorscheme darkblue  "设置工作模式为
    colorscheme desert " my theme for gui
else
    "colorscheme evening  "设置工作模式为夜间
    colorscheme desert " my theme for gui
endif

"字体的设置
""--------------------------------------
"guifont=Courier_New:h12:cANSI
"set guifont=Terminal\ 10
"set guifont=AR\ PL\ New\ Sung\ 10
"--------------------------------------
"set guifont=Bitstream\ Vera\ Sans\ Mono\ 9 "正在使用的
"set guifont=Bitstream_Vera_Sans_Mono:h10:cANSI "记住空格用下划线代替哦
"set guifont=Monaco:h10:cANSI "记住空格用下划线代替哦
set guifont=Bitstream\ Vera\ Sans\ Mono\ 10 "正在使用的
"set gfw=幼圆:h10:cGB2312 
"
"-----------------------------------------
function Do_CsTag()
    if(executable('cscope') && has("cscope") )
        if(g:iswindows!=1)
            silent! execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' > cscope.files"
        else
            silent! execute "!dir /b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"
        endif
        silent! execute "!cscope -b"
        if filereadable("cscope.out")
            execute "cs add cscope.out"
        endif
    endif
endf
" cscope setting
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("cscope")
"     set csprg=/usr/bin/cscope
"     set csto=1
"     set cst
"     set nocsverb
"     " add any database in current directory
     if filereadable("../cscope.out")
         cs add ../cscope.out
     "if filereadable("cscope.out")
         "cs add cscope.out
     endif
     set csverb
     "----add ---
    set cscopequickfix=s-,c-,d-,i-,t-,e-
    "set csto=0
    set cst
    set csverb
    "----add end---
endif
"-----------------------------------------
"
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" for omnicppcomplete
set nocp
"filetype plugin on
"Thus to build recursively a ctags database from the current directory, the command looks like this:
"ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .
"You can add a map in your |.vimrc| file, eg: >
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
"You can ensure that the 'tags' option is set properly by executing the following command: >
"----------------------------------------
":tselect MyClass
"----------------------------------------
"You can enable/disable the global scope search by setting the
"OmniCpp_GlobalScopeSearch option.
"Possible values are : 
"        0 = disabled
"        1 = enabled
"        [default=1] >
let OmniCpp_GlobalScopeSearch = 1
"----------------------------------------
" You can cHANGE the 'using namespace' search behaviour by setting the
" OmnicPP_namespaceSearch option.
" Possible values are :
" 0 = namespaces disabled
" 1 = search namespaces in the current buffer
" 2 = search namespaces in the current buffer and in included files
" [default=1] >
let OmniCpp_NamespaceSearch = 1
"----------------------------------------
" Note: This option can be use when you have friend classes in your project (the 
" script does not support friend classes).
" Possible values are :
" 0 = auto
" 1 = always show all members
" [default=0] >
let OmniCpp_DisplayMode = 0
"----------------------------------------
" By default, in the |omnicpp-popup| menu, you will see the scope of a match in 
" the last column. You can remove this column and add the scope at the beginning
" of match abbreviation.
" eg: 
"
" OmniCpp_ShowScopeInAbbr = 0
"         +-------------------------------------+
"         |method1(   f  +  MyNamespace::MyClass|
"         |_member1   m  +  MyNamespace::MyClass|
"         |_member2   m  #  MyNamespace::MyClass|
"         |_member3   m  -  MyNamespace::MyClass|
"         +-------------------------------------+
"
" OmniCpp_ShowScopeInAbbr = 1
"         +-------------------------------------+
"         |MyNamespace::MyClass::method1(   f + |
"         |MyNamespace::MyClass::_member1   m + |
"         |MyNamespace::MyClass::_member2   m # |
"         |MyNamespace::MyClass::_member3   m - |
"         +-------------------------------------+
"
" Possible values are :
"         0 = don't show scope in abbreviation
"         1 = show scope in abbreviation and remove the last column
"         [default=0] >
let OmniCpp_ShowScopeInAbbr = 0
"Possible values are:
"        0 = don't display prototype in abbreviation
"        1 = display prototype in abbreviation
"        [default=0] >
"        
let OmniCpp_ShowPrototypeInAbbr = 0
"----------------------------------------
"This option allows to show/hide the access information ('+', '#', '-') in the 
"popup menu.
"
"Possible values are:
"        0 = hide access
"        1 = show access
"        [default=1] >
"        
let OmniCpp_ShowAccess = 1
"----------------------------------------
"This option can be use if you don't want to parse using namespace declarations
"in included files and want to add namespaces that are always used in your
" project.
"
" Possible values are : 
"         List of String
"         [default=[]] >
let OmniCpp_DefaultNamespaces = []
"----------------------------------------
"下面的设置用于当用户预先声明namespace时也能自动补全代码（如使用using std::string）
let OmniCpp_DefaultNamespaces = ["std"]
"设置代码提示窗口的颜色（默认为粉红色，如附图1,下面的设置的效果如附图2）
"   highlight Pmenu ctermbg=13 guibg=LightGray
"   highlight PmenuSel ctermbg=7 guibg=DarkBlue guifg=White
"   highlight PmenuSbar ctermbg=7 guibg=DarkGray
"   highlight PmenuThumb guibg=Black

"设置tags目录，可以根据自己的设置自动调整
"set tags+=C:\ctags56\stltags
"set tags+=C:\ctags56\cpptags
" ------------------------------
"----------------------------------------

"----------------------------------------
"for cmake
:autocmd BufRead,BufNewFile *.cmake,CMakeLists.txt,*.cmake.in runtime! indent/cmake.vim 
:autocmd BufRead,BufNewFile *.cmake,CMakeLists.txt,*.cmake.in setf cmake
:autocmd BufRead,BufNewFile *.ctest,*.ctest.in setf cmake
"----------------------------------------
"

"----------------------------------------
"for eclim
"   let g:EclimHome = '/usr/share/vim/vimfiles/eclim'
"   let g:EclimEclipseHome = '/usr/share/eclipse'
"   let g:EclimTaglistEnabled=0 
"   >>> Add the following to your ~/.vimrc:
"
"   let g:EclimHome = '/usr/share/vim/vimfiles/eclim'
"   let g:EclimEclipseHome = '/usr/share/eclipse'
"
"   >>> Copy the /usr/share/vim/vimfiles/eclim/resources
"   >>> directory to ~/.eclim/resources

"----------------------------------------
" :AutoComplPopDisable 禁止自动弹出补全
